package com.zhang;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zhang.domain.User;
import com.zhang.mapper.UserMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class Update {

    @Autowired
    private UserMapper userMapper;

    //1.根据条件构造器 修改(多个)
    //(1)QueryWrapper
    @Test
    public void test1() {

        //1.修改条件
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username","刘备");

        //2.修改的内容
        User user = new User(0,"刘备1","1234",null);

        //3.执行修改
        userMapper.update(user,wrapper);

    }

    //(2)UpdateWrapper 有错误!!!!!!!!!!!!!
    @Test
    public void test2() {
        //1.修改条件+修改内容
        UpdateWrapper<User> wrapper = new UpdateWrapper<>();
        wrapper.eq("username","关羽").set("password",111);

        //2.执行修改
        userMapper.update(null,wrapper);

    }




    //2.根据Id 修改(单个)
    @Test
    public void test3() {
        User user = new User(3,"刘备2","111",null);
        userMapper.updateById(user);

    }

}
